package com.books.controller.comment;

import com.books.model.bo.Result;
import com.books.model.entity.comment.Comment;

import com.books.model.entity.pianhao.Hobbies;
import com.books.service.comment.ICommentService;
import com.books.service.hobbies.HobbiesService;
import com.books.service.order.impl.OrderListServerImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author 饿熊的咆哮
 * @Date 2021/10/14 10:00
 * @Version 1.0
 */
@Controller
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    private ICommentService commentService;
    @Autowired
    private OrderListServerImpl orderListServer;
    @Autowired
    private HobbiesService hobbiesService;
    @Autowired
    private Hobbies hobbies;

    @GetMapping("/comment")
    public String comment(){
        return "comment/comment";
    }

    @PostMapping("/addComment")
    @ResponseBody
    public Result addComment(Comment comment,String id){
        commentService.addComment(comment);
        orderListServer.upStatusId (1,id);


//        Hobbies hobbies = new Hobbies ();
        hobbies.setId (null);
        hobbies.setUid (comment.getPeopleId ());
        hobbies.setPid (comment.getBookId ());
        hobbies.setVal (comment.getCommentStar ());
        hobbies.setTime (comment.getCommentTime ());
        hobbiesService.addHobbies (hobbies);

        return new Result("200","添加成功");
    }
}
